package compose.project.demo

import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.defaultMinSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.lazy.LazyRow
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.Button
import androidx.compose.material.ButtonDefaults
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Text
import androidx.compose.material.TextField
import androidx.compose.material.TextFieldDefaults
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.input.VisualTransformation
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp

@Composable
fun Test() {
    MaterialTheme {

        // 定义圆角的形状，例如16dp的圆角
        val shape = RoundedCornerShape(
            topStart = 16.dp,
            topEnd = 16.dp,
            bottomStart = 16.dp,
            bottomEnd = 16.dp
        )
        val shapeCol = RoundedCornerShape(8.dp)
        val types = listOf("打车", "顺风车", "驾车", "公交地铁", "骑行", "步行")
        var showContent by remember { mutableStateOf("驾车") }


        // 应用的其余部分
        Column(
            modifier = Modifier
                .width(450.dp)
                .background(color = Color.White, shape = shape) // 设置背景色和圆角形状
                .padding(start = 12.dp, top = 8.dp, end = 12.dp, bottom = 8.dp),
        ) {
            Row {

//                Image(
//                    painter = painterResource(Res.drawable.back),
//                    contentDescription = "资源图片",
//                    modifier = Modifier
//                        .padding(end = 10.dp, top = 10.dp)
//                        .height(28.dp), // 设置图片高度
//                    contentScale = ContentScale.Fit // 根据需要调整图片的缩放行为
//                )
                Row(
                    modifier = Modifier
                        .background(color = Color(0xFFF7F7F7), shape = shapeCol) // 设置灰色背景和圆角形状
                        .fillMaxWidth()
                        .padding(start = 16.dp, end = 16.dp), // 如果需要内边距
                    horizontalArrangement = Arrangement.SpaceBetween,
                    verticalAlignment = Alignment.CenterVertically
                ) {
                    Column(
                        modifier = Modifier.width(190.dp)
                    ) {
                        TextField(
                            value = "我的位置",
                            onValueChange = { /* 处理文本变化的回调 */ },
                            visualTransformation = VisualTransformation.None, // 视觉转换
                            modifier = Modifier.height(51.dp).padding(0.dp),
                            textStyle = TextStyle(fontSize = 14.sp, fontWeight = FontWeight.Bold),
                            singleLine = true, // 单行显示
                            placeholder = { Text(text = "当前位置", fontSize = 14.sp) },
                            colors = TextFieldDefaults.outlinedTextFieldColors(
                                backgroundColor = Color(0xFFF7F7F7), // 输入框背景色
                                textColor = Color.Black,
                                focusedBorderColor = Color.Transparent, // 聚焦时的边框颜色
                                unfocusedBorderColor = Color.Transparent // 未聚焦时的边框颜色
                            ),
                        )
                        TextField(
                            value = "",
                            onValueChange = { /* 处理文本变化的回调 */ },
                            visualTransformation = VisualTransformation.None, // 视觉转换
                            modifier = Modifier.height(51.dp).padding(0.dp),
                            textStyle = TextStyle(fontSize = 14.sp),
                            singleLine = true, // 单行显示
                            placeholder = { Text("输入终点", fontSize = 14.sp) },
                            colors = TextFieldDefaults.outlinedTextFieldColors(
                                backgroundColor = Color(0xFFF7F7F7), // 输入框背景色
                                textColor = Color.Black,
                                focusedBorderColor = Color.Transparent, // 聚焦时的边框颜色
                                unfocusedBorderColor = Color.Transparent // 未聚焦时的边框颜色
                            )
                        )
                    }

                    Row {
//                        Image(
//                            painter = painterResource(Res.drawable.add),
//                            contentDescription = "资源图片",
//                            modifier = Modifier
//                                .padding(end = 8.dp)
//                                .width(25.dp)
//                                .height(25.dp), // 设置图片高度
//                            contentScale = ContentScale.Fit // 根据需要调整图片的缩放行为
//                        )
//                        Image(
//                            painter = painterResource(Res.drawable.change),
//                            contentDescription = "资源图片",
//                            modifier = Modifier
//                                .padding(end = 8.dp)
//                                .width(25.dp)
//                                .height(25.dp), // 设置图片高度
//                            contentScale = ContentScale.Fit // 根据需要调整图片的缩放行为
//                        )
//                        Image(
//                            painter = painterResource(Res.drawable.mkf),
//                            contentDescription = "资源图片",
//                            modifier = Modifier
//                                .padding(end = 8.dp)
//                                .width(25.dp)
//                                .height(25.dp), // 设置图片高度
//                            contentScale = ContentScale.Fit // 根据需要调整图片的缩放行为
//                        )
                    }
                }
            }
            Box(
                modifier = Modifier.padding(10.dp),
                contentAlignment = Alignment.TopEnd
            ) {


                LazyRow {
                    items(types.size) {
                        if (showContent == types[it]) {
                            Button(
                                modifier = Modifier
                                    .height(25.dp)
                                    .defaultMinSize(1.dp, 1.dp)
                                    .padding(top = 0.dp, end = 30.dp),
                                contentPadding = PaddingValues(0.dp),
                                shape = shape,
                                onClick = { showContent = types[it] },
                                colors = ButtonDefaults.buttonColors(
                                    backgroundColor = Color(0xFFE8F2FE),
                                    contentColor = Color(0xFFE8F2FE)
                                )
                            ) {
                                Text(
                                    text = types[it],
                                    color = Color(0xff3366dd),
                                    fontWeight = FontWeight.Bold,
                                    fontSize = 15.sp,
                                )
                            }
                        } else {
                            Text(
                                text = types[it],
                                modifier = Modifier.padding(end = 30.dp)
                                    .clickable {
                                        showContent = types[it]
                                    },
                                color = Color.Gray,
                                fontSize = 15.sp,
                            )
                        }
                    }
                }

                Column(
                    modifier = Modifier
                        .width(30.dp)
                        .background(
                            brush = Brush.linearGradient(
                                colors = listOf(Color.White, Color(0x00000000)), // 定义渐变的颜色
                                start = Offset(20.0f, 0.0f),
                                end = Offset(0.0f, 0.0f)
                            )
                        )
                ) {
//                    Image(
//                        painter = painterResource(Res.drawable.down),
//                        contentDescription = "资源图片",
//                        modifier = Modifier.height(25.dp), // 设置图片高度
//                        contentScale = ContentScale.Fit // 根据需要调整图片的缩放行为
//                    )
                }
            }
        }
    }
}